var pageParams;

function addLoad() {
}

//返回值为需不需要关闭窗口
function yesOperator() {
    var retValue = addData();
    return retValue;
}

function updateLoad() {
    var params = $$.getQueryString();
    $$.ajax({
        url: "/rest/BaseTimerBusiness/query",
        data: {
            id: params.rowId
        },
        success: function (data) {
            $("#b_id").val(data.id);
            $("#b_appCode").val(data.appCode);
            $("#b_timerName").val(data.timerName);
            $("#b_timerCycle").val(data.timerCycle);
            $("#b_timerUnit").val(data.timerUnit);
            $("#b_timerStart").val(data.timerStart);
            $("#b_timerOrigin").val(data.timerOrigin);
            $("#b_timerGroup").val(data.timerGroup);
            $("#b_timerBusi").val(data.timerBusi);
            $("#b_status").val(data.status);
            $("#b_rowSort").val(data.rowSort);
            $("#b_remarks").val(data.remarks);

            var status = data.status;
            $("input[name^='b_status_']").each(function () {
                if ($(this).val() == status) {
                    this.checked = 'checked';
                }
            });

            $("#b_timerCodeOld").val(data.timerCode);
        }
    });
}

function validForm() {
    return $('#theform').valid();
}

function addData() {
    var param = {};
    var validFormRet;
    $$.form({
        async: false,
        able: function () {
            validFormRet = false;
        },
        checkForm: validForm,
        success: function () {
            validFormRet = true;
        }
    });
    return validFormRet;
}

function forwardCalcValid() {
    $("#theform").validate({
        rules: {
            b_appCode: {

                required: true,

                minlength: 1,
                number: false
            },
            b_timerName: {

                required: true,

                minlength: 1,
                number: false
            },
            b_timerCycle: {

                required: true,

                minlength: 1,
                number: false
            },
            b_timerUnit: {

                required: true,

                minlength: 1,
                number: false
            },
            b_timerStart: {

                required: true,

                minlength: 1,
                number: false
            },
            b_timerOrigin: {

                required: true,

                minlength: 1,
                number: false
            },
            b_timerGroup: {

                required: true,

                minlength: 1,
                number: false
            },
            b_timerBusi: {

                required: true,

                minlength: 1,
                number: false
            },
            b_status: {

                required: true,

                minlength: 1,
                number: false
            },
            b_rowSort: {

                required: true,

                minlength: 1,
                number: false
            },

            b_rowSort: {
                required: true,
                minlength: 3,
                isInteger: false,
            }
        },
        errorPlacement: function (error, element) {
            error.appendTo(element.parent());
        },
        errorElement: "span",
        errorClass: "errortips",
        success: 'valid',
        messages: {
            b_appCode: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_timerName: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_timerCycle: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_timerUnit: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_timerStart: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_timerOrigin: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_timerGroup: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_timerBusi: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_status: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },
            b_rowSort: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",
                number: "请输入数字",
            },

            b_rowSort: {
                required: " (必填字段)",
                minlength: " (不能少于3位编号)",
                number: "请输入数字",
            }
        },
    });
}

$(function () {
    pageParams = $$.getQueryString();
    forwardCalcValid();
    $("input[name^='b_status']").click(function () {
        $("#b_status").val($(this).val());
    });
});
/*
jQuery.validator.addMethod("isCode", function(value, element) {
    //校验编码是否存在
    var timerCodeOld=$("#b_timerCodeOld").val();
    var timerCode=$("#b_timerCode").val();
    if(timerCodeOld==timerCode){
        return true;
    }else{
            var args={};
            args.c_timerCode_1=$("#b_timerCode").val();
            args.page=0;
            args.pageSize=5;
            args.isPage=1;
            var exists;
            $$.ajax({
                url: "/bootstrap/basegrid/BaseTimerBusiness/list",
                async:false,
                data: args,
                success: function (data) {
                    if(data.length && data.length>0){
                        exists=true;
                     }else{
                        exists=false;
                    }
                }
            });
	        if(exists){
	            $(element).data('error-msg','编码不能重复！');
	            return false;
	        }
        return true;
    }
}, function(params, element) {
    return $(element).data('error-msg');
});
*/
